﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:rep="urn:report-extended-utilities"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl rep">
  <xsl:output method="xml" indent="yes"/>
  <xsl:param name="report-name">SharePoint Sites Collections Frequency</xsl:param>
  <xsl:param name="report-chart-type">Pie</xsl:param>
  <xsl:param name="report-date" />
  <xsl:template match="/">
    <xsl:variable name="report-legend-title">Web applications</xsl:variable>
    <Report>
      <xsl:attribute name="Name">
        <xsl:value-of select="$report-name"/>
      </xsl:attribute>
      <xsl:attribute name="ChartType">
        <xsl:value-of select="$report-chart-type"/>
      </xsl:attribute>
      <xsl:attribute name="LegendTitle">
        <xsl:value-of select="$report-legend-title"/>
      </xsl:attribute>
      <Filters>
        <Filter Name="All" FilterAttribute="WebApplication" FilterValue="ALL" />
        <xsl:for-each select="//WebApplications/WebApplication">
          <Filter Name="{@Url}" FilterAttribute="WebApplication" FilterValue="{@Id}" />
        </xsl:for-each>
      </Filters>
      <Series>
      	<Serie Name="All">
          <Item Name="&gt;= 90 days" WebApplication="ALL" Date="{$report-date}">
            <xsl:attribute name="Value">
              <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &gt;= 90])"/>
            </xsl:attribute>
          </Item>
              <Item Name="&lt; 90 days" WebApplication="ALL" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &lt; 90 and rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &gt;= 30])"/>
                </xsl:attribute>
              </Item>
              <Item Name="&gt; 30 days" WebApplication="ALL" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &lt; 30 and rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &gt;= 7])"/>
                </xsl:attribute>
              </Item>
              <Item Name="&gt; 7 days" WebApplication="ALL" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &lt; 7 and rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &gt;= 1])"/>
                </xsl:attribute>
              </Item>
              <Item Name="&gt; 1 day" WebApplication="ALL" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(//WebApplications/WebApplication/Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &lt; 1])"/>
                </xsl:attribute>
              </Item>
      	</Serie>
          <xsl:for-each select="//WebApplications/WebApplication">
            <xsl:variable name="WebAppId" select="@Id" />
        	<Serie Name="{@Url}">
              <Item Name="&gt;= 90 days" WebApplication="{$WebAppId}" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &gt;= 90])"/>
                </xsl:attribute>
              </Item>
              <Item Name="&lt; 90 days" WebApplication="{$WebAppId}" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &lt; 90 and rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &gt;= 30])"/>
                </xsl:attribute>
              </Item>
              <Item Name="&lt; 30 days" WebApplication="{$WebAppId}" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &lt; 30 and rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &gt;= 7])"/>
                </xsl:attribute>
              </Item>
              <Item Name="&lt; 7 days" WebApplication="{$WebAppId}" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &lt; 7 and rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &gt;= 1])"/>
                </xsl:attribute>
              </Item>
              <Item Name="&lt; 1 day" WebApplication="{$WebAppId}" Date="{$report-date}">
                <xsl:attribute name="Value">
                  <xsl:value-of select="count(Sites/Site[rep:DateDiff($report-date,@LastContentModifiedDate,  'd') &lt; 1])"/>
                </xsl:attribute>
              </Item>
	        </Serie>
          </xsl:for-each>
      </Series>
    </Report>
  </xsl:template>
</xsl:stylesheet>
